import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {BusinessUserVO, BusinessUserForm, BusinessUserQuery} from '@/api/business/businessUser/types';

/**
 * 查询用户信息列表
 * @param query
 * @returns {*}
 */

export const listBusinessUser = (query?: BusinessUserQuery): AxiosPromise<BusinessUserVO[]> => {
  return request({
    url: '/business/businessUser/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询用户信息详细
 * @param userId
 */
export const getBusinessUser = (userId: string | number): AxiosPromise<BusinessUserVO> => {
  return request({
    url: '/business/businessUser/' + userId,
    method: 'get'
  });
};

/**
 * 新增用户信息
 * @param data
 */
export const addBusinessUser = (data: BusinessUserForm) => {
  return request({
    url: '/business/businessUser',
    method: 'post',
    data: data
  });
};

/**
 * 修改用户信息
 * @param data
 */
export const updateBusinessUser = (data: BusinessUserForm) => {
  return request({
    url: '/business/businessUser',
    method: 'put',
    data: data
  });
};

/**
 * 删除用户信息
 * @param userId
 */
export const delBusinessUser = (userId: string | number | Array<string | number>) => {
  return request({
    url: '/business/businessUser/' + userId,
    method: 'delete'
  });
};
//充值
export const giveApi = (params: any) => {
  return request({
    url: '/business/vip/give',
    method: 'post',
    params: params
  });
};

interface UserNode {
  id: number
  name: string
  avatar: string
  children?: UserNode[]
}

export const getRelationApi = (userId: string | number): AxiosPromise<UserNode[]> => {
  return request({
    url: '/business/businessUser/getRelation',
    method: 'get',
    params: {userId}
  });
};
